﻿using System.Linq;
using System;
using System.Collections.Generic;

namespace CoolCode.Data.Linq
{
    public interface ITable<T> : IOrderedQueryable<T>
    {
        void Store (T TEntity);
        void Delete (T TEntity);
        void Delete(System.Linq.Expressions.Expression<Func<T, bool>> predicate);
        void StoreAll (System.Collections.Generic.IEnumerable<T> TList);
        void DeleteAll (System.Collections.Generic.IEnumerable<T> TList);
    }

   //public interface ISubmit
   //{
   //    bool IsChanged { get; set; } 
   //}

   public static class TableExtention
   {
       public static bool Contains<T>(this ITable<T> table, Func<T, bool> predicate)
       {
           return table.Where<T>(predicate).Count()>0;
       }

       public static IList <T> Query<T>(this ITable<T> table, Func<T, bool> predicate)
       {
           return table.Where<T>(predicate).ToList() ;
       }

       public static IList<T> Query<T>(this ITable<T> table)
       {
           return (from q in  table select q).ToList();
       }
   }


}
